<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>分类: 技术教程 | 小小程序员</title><meta name="author" content="十一星野"><meta name="copyright" content="十一星野"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="由于 K8S 目前实在是太火了，之前一直说要给 mall 项目出个 K8S 部署方案，这次它来啦！在更新完 K8S 系列教程后，是时候来波实践了，拿 mall-swarm 项目来实践真的是刚刚好。如果你有在 Docker 下部署该项目的经历，而且已经学习了我的 K8S 系列教程的话，相信你能够轻松上手！  #服务器规划 我们先来说下服务器规划吧，之前一直使用的是单机部署所有服务，这次我们使用两台">
<meta property="og:type" content="article">
<meta property="og:title" content="mall-swarm微服务项目在K8S下的最佳实践">
<meta property="og:url" content="https://ko25891wan.gitlab.io/2024/01/98cfc2cb76b4.html">
<meta property="og:site_name" content="小小程序员">
<meta property="og:description" content="由于 K8S 目前实在是太火了，之前一直说要给 mall 项目出个 K8S 部署方案，这次它来啦！在更新完 K8S 系列教程后，是时候来波实践了，拿 mall-swarm 项目来实践真的是刚刚好。如果你有在 Docker 下部署该项目的经历，而且已经学习了我的 K8S 系列教程的话，相信你能够轻松上手！  #服务器规划 我们先来说下服务器规划吧，之前一直使用的是单机部署所有服务，这次我们使用两台">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png">
<meta property="article:published_time" content="2024-01-21T09:30:21.000Z">
<meta property="article:modified_time" content="2024-01-21T09:30:21.542Z">
<meta property="article:author" content="十一星野">
<meta property="article:tag" content="宅男,热血">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://ko25891wan.gitlab.io/2024/01/98cfc2cb76b4.html"><link rel="preconnect" href="//fastly.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.5.1/css/all.min.css"><link rel="stylesheet" href="https://cdn.staticfile.org/fancyapps-ui/5.0.32/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"top_n_per_article":1,"unescape":false,"languages":{"hits_empty":"找不到您查询的内容：${query}","hits_stats":"共找到 ${hits} 篇文章"}},
  translate: {"defaultEncoding":1,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"简"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlight.js","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":200},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: true
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.staticfile.org/egjs-infinitegrid/4.11.0/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: true,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '分类: 技术教程',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2024-01-21 17:30:21'
}</script><script>(win=>{
      win.saveToLocal = {
        set: (key, value, ttl) => {
          if (ttl === 0) return
          const now = Date.now()
          const expiry = now + ttl * 86400000
          const item = {
            value,
            expiry
          }
          localStorage.setItem(key, JSON.stringify(item))
        },
      
        get: key => {
          const itemStr = localStorage.getItem(key)
      
          if (!itemStr) {
            return undefined
          }
          const item = JSON.parse(itemStr)
          const now = Date.now()
      
          if (now > item.expiry) {
            localStorage.removeItem(key)
            return undefined
          }
          return item.value
        }
      }
    
      win.getScript = (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        script.onerror = reject
        script.onload = script.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          script.onload = script.onreadystatechange = null
          resolve()
        }

        Object.keys(attr).forEach(key => {
          script.setAttribute(key, attr[key])
        })

        document.head.appendChild(script)
      })
    
      win.getCSS = (url, id = false) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onerror = reject
        link.onload = link.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          link.onload = link.onreadystatechange = null
          resolve()
        }
        document.head.appendChild(link)
      })
    
      win.activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
        if (t === 'dark') activateDarkMode()
        else if (t === 'light') activateLightMode()
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
      const detectApple = () => {
        if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
          document.documentElement.classList.add('apple')
        }
      }
      detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>(()=>{
  const $loadingBox = document.getElementById('loading-box')
  const $body = document.body
  const preloader = {
    endLoading: () => {
      $body.style.overflow = ''
      $loadingBox.classList.add('loaded')
    },
    initLoading: () => {
      $body.style.overflow = 'hidden'
      $loadingBox.classList.remove('loaded')
    }
  }

  preloader.initLoading()
  window.addEventListener('load',() => { preloader.endLoading() })

  if (false) {
    document.addEventListener('pjax:send', () => { preloader.initLoading() })
    document.addEventListener('pjax:complete', () => { preloader.endLoading() })
  }
})()</script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">120</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">4</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">22</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-heartbeat"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-tools"></i><span> 工具</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/md_editor/"><i class="fa-fw fas fa-pen"></i><span> MDEditor_my</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="not-top-img" id="page-header"><nav id="nav"><span id="blog-info"><a href="/" title="小小程序员"><span class="site-name">小小程序员</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-heartbeat"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-tools"></i><span> 工具</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/md_editor/"><i class="fa-fw fas fa-pen"></i><span> MDEditor_my</span></a></li></ul></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav></header><main class="layout" id="content-inner"><div id="post"><div id="post-info"><h1 class="post-title">mall-swarm微服务项目在K8S下的最佳实践</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2024-01-21T09:30:21.000Z" title="发表于 2024-01-21 17:30:21">2024-01-21</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2024-01-21T09:30:21.542Z" title="更新于 2024-01-21 17:30:21">2024-01-21</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/">技术教程</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/mall/">mall</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/mall/%E9%83%A8%E7%BD%B2%E7%AF%87/">部署篇</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2.7k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>11分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="mall-swarm微服务项目在K8S下的最佳实践"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div><article class="post-content" id="article-container"><blockquote>
<p>由于 K8S 目前实在是太火了，之前一直说要给 mall 项目出个 K8S 部署方案，这次它来啦！在更新完 K8S 系列教程后，是时候来波实践了，拿 <code>mall-swarm</code> 项目来实践真的是刚刚好。如果你有在 Docker 下部署该项目的经历，而且已经学习了我的 K8S 系列教程的话，相信你能够轻松上手！</p>
</blockquote>
<h2 id="服务器规划"><a href="#服务器规划" class="headerlink" title="#服务器规划"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/deploy/mall_swarm_deploy_k8s.html#%E6%9C%8D%E5%8A%A1%E5%99%A8%E8%A7%84%E5%88%92">#</a>服务器规划</h2><blockquote>
<p>我们先来说下服务器规划吧，之前一直使用的是单机部署所有服务，这次我们使用两台服务器来部署。</p>
</blockquote>
<ul>
<li><p>基础服务器（192.168.3.101）：用于部署<code>mall-swarm</code>的依赖服务，包括MySql、Redis、Elasticsearch等与应用无关的服务，采用Docker方式来部署。</p>
</li>
<li><p>应用服务器（192.168.3.102）：用于部署<code>mall-swarm</code>的应用服务，包括mall-admin、mall-portal、mall-search等应用服务，采用K8S方式来部署。</p>
</li>
</ul>
<h2 id="镜像打包及推送"><a href="#镜像打包及推送" class="headerlink" title="#镜像打包及推送"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/deploy/mall_swarm_deploy_k8s.html#%E9%95%9C%E5%83%8F%E6%89%93%E5%8C%85%E5%8F%8A%E6%8E%A8%E9%80%81">#</a>镜像打包及推送</h2><blockquote>
<p>为了方便部署，我们把<code>mall-swarm</code>的所有应用镜像都上传到Docker Hub上去。</p>
</blockquote>
<ul>
<li>首先修改项目根目录下的<code>pom.xml</code>文件；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&lt;properties&gt;</span><br><span class="line">    &lt;!--改为你自己的Docker服务远程访问地址--&gt;</span><br><span class="line">    &lt;docker.host&gt;http://192.168.3.101:2375&lt;/docker.host&gt;</span><br><span class="line">&lt;/properties&gt;</span><br></pre></td></tr></table></figure>

<ul>
<li>使用Maven插件将所有镜像打包到Linux服务器上，直接使用根项目下的<code>package</code>命令即可；</li>
</ul>
<p><img src="https://www.macrozheng.com/assets/mall_swarm_deploy_k8s_01-74f008a8.png"></p>
<ul>
<li>修改所有镜像标签名称，修改本地镜像标签名称为远程镜像标签名称；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">docker tag mall/mall-gateway:1.0-SNAPSHOT macrodocker/mall-gateway:1.0-SNAPSHOT</span><br><span class="line">docker tag mall/mall-auth:1.0-SNAPSHOT macrodocker/mall-auth:1.0-SNAPSHOT</span><br><span class="line">docker tag mall/mall-monitor:1.0-SNAPSHOT macrodocker/mall-monitor:1.0-SNAPSHOT</span><br><span class="line">docker tag mall/mall-admin:1.0-SNAPSHOT macrodocker/mall-admin:1.0-SNAPSHOT</span><br><span class="line">docker tag mall/mall-portal:1.0-SNAPSHOT macrodocker/mall-portal:1.0-SNAPSHOT</span><br><span class="line">docker tag mall/mall-search:1.0-SNAPSHOT macrodocker/mall-search:1.0-SNAPSHOT</span><br></pre></td></tr></table></figure>

<ul>
<li>修改完成后查询<code>macrodocker</code>相关镜像显示如下，<code>macrodocker</code>为我们在Docker Hub上的仓库地址；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">[root@local-linux ~]# docker images |grep macrodocker</span><br><span class="line">macrodocker/mall-auth      1.0-SNAPSHOT        72df5f91f2d7        9 minutes ago       699MB</span><br><span class="line">macrodocker/mall-gateway   1.0-SNAPSHOT        4055dfc1e601        9 minutes ago       708MB</span><br><span class="line">macrodocker/mall-monitor   1.0-SNAPSHOT        492d9bb4375c        9 minutes ago       696MB</span><br><span class="line">macrodocker/mall-portal    1.0-SNAPSHOT        8dd79675f40c        10 minutes ago      719MB</span><br><span class="line">macrodocker/mall-search    1.0-SNAPSHOT        f0d0d80c590f        10 minutes ago      734MB</span><br><span class="line">macrodocker/mall-admin     1.0-SNAPSHOT        15737ce903a9        11 minutes ago      715MB</span><br></pre></td></tr></table></figure>

<ul>
<li>之后推送镜像到Docker Hub，如果你不想自己推送镜像，可以使用我已经上传好到镜像。</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"># 登录Docker Hub</span><br><span class="line">docker login</span><br><span class="line"># 推送到远程仓库</span><br><span class="line">docker push macrodocker/mall-gateway:1.0-SNAPSHOT</span><br><span class="line">docker push macrodocker/mall-auth:1.0-SNAPSHOT</span><br><span class="line">docker push macrodocker/mall-monitor:1.0-SNAPSHOT</span><br><span class="line">docker push macrodocker/mall-admin:1.0-SNAPSHOT</span><br><span class="line">docker push macrodocker/mall-portal:1.0-SNAPSHOT</span><br><span class="line">docker push macrodocker/mall-search:1.0-SNAPSHOT</span><br></pre></td></tr></table></figure>

<h2 id="基础服务器部署"><a href="#基础服务器部署" class="headerlink" title="#基础服务器部署"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/deploy/mall_swarm_deploy_k8s.html#%E5%9F%BA%E7%A1%80%E6%9C%8D%E5%8A%A1%E5%99%A8%E9%83%A8%E7%BD%B2">#</a>基础服务器部署</h2><blockquote>
<p>我们依然使用Docker来部署依赖服务，<code>mall-swarm</code>运行需要的依赖服务如下，使用Docker Compose脚本安装更方便，Docker Compose使用请参考：<a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/reference/docker_compose.html">《使用Docker Compose部署SpringBoot应用》</a> 。</p>
</blockquote>
<table>
<thead>
<tr>
<th>组件</th>
<th>版本号</th>
</tr>
</thead>
<tbody><tr>
<td>Mysql</td>
<td>5.7</td>
</tr>
<tr>
<td>Redis</td>
<td>5.0</td>
</tr>
<tr>
<td>MongoDb</td>
<td>4.3.5</td>
</tr>
<tr>
<td>RabbitMq</td>
<td>3.7.15</td>
</tr>
<tr>
<td>Nginx</td>
<td>1.10</td>
</tr>
<tr>
<td>Elasticsearch</td>
<td>7.6.2</td>
</tr>
<tr>
<td>Logstash</td>
<td>7.6.2</td>
</tr>
<tr>
<td>Kibana</td>
<td>7.6.2</td>
</tr>
<tr>
<td>Nacos</td>
<td>1.3.0</td>
</tr>
</tbody></table>
<ul>
<li>本项目已经提供好了Docker Compose脚本，直接执行如下命令即可，脚本地址：<a target="_blank" rel="noopener" href="https://github.com/macrozheng/mall-swarm/blob/master/document/docker/docker-compose-env.yml">https://github.com/macrozheng/mall-swarm/blob/master/document/docker/docker-compose-env.yml</a></li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker-compose -f docker-compose-env.yml up -d</span><br></pre></td></tr></table></figure>

<ul>
<li><p>某些系统组件无法启动问题，具体参考：<a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/deploy/mall_deploy_docker_compose.html">《mall在Linux环境下的部署（基于Docker Compose）》</a></p>
</li>
<li><p>部署完成后，查看Docker中运行的服务显示如下。</p>
</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">[root@local-linux ~]# docker ps</span><br><span class="line">CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS                                                                                        NAMES</span><br><span class="line">fef5695319d1        nacos/nacos-server:1.3.0     &quot;bin/docker-startup.…&quot;   3 months ago        Up 6 hours          0.0.0.0:8848-&gt;8848/tcp                                                                       nacos-registry</span><br><span class="line">e7ec37fcafda        elasticsearch:7.6.2          &quot;/usr/local/bin/dock…&quot;   3 months ago        Up 6 hours          0.0.0.0:9200-&gt;9200/tcp, 0.0.0.0:9300-&gt;9300/tcp                                               elasticsearch</span><br><span class="line">427f0176c426        mongo:4.2.5                  &quot;docker-entrypoint.s…&quot;   3 months ago        Up 6 hours          0.0.0.0:27017-&gt;27017/tcp                                                                     mongo</span><br><span class="line">5618ed50942a        redis:5                      &quot;docker-entrypoint.s…&quot;   3 months ago        Up 6 hours          0.0.0.0:6379-&gt;6379/tcp                                                                       redis</span><br><span class="line">1744f412c6f4        rabbitmq:3.7.15-management   &quot;docker-entrypoint.s…&quot;   3 months ago        Up 6 hours          4369/tcp, 5671/tcp, 0.0.0.0:5672-&gt;5672/tcp, 15671/tcp, 25672/tcp, 0.0.0.0:15672-&gt;15672/tcp   rabbitmq</span><br><span class="line">6b26f63dfad6        mysql:5.7                    &quot;docker-entrypoint.s…&quot;   3 months ago        Up 6 hours          0.0.0.0:3306-&gt;3306/tcp, 33060/tcp                                                            mysql</span><br></pre></td></tr></table></figure>

<h2 id="应用服务器部署"><a href="#应用服务器部署" class="headerlink" title="#应用服务器部署"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/deploy/mall_swarm_deploy_k8s.html#%E5%BA%94%E7%94%A8%E6%9C%8D%E5%8A%A1%E5%99%A8%E9%83%A8%E7%BD%B2">#</a>应用服务器部署</h2><blockquote>
<p>我们将把<code>mall-swarm</code>中所有应用服务都部署到K8S上，使用Rancher来进行可视化管理。</p>
</blockquote>
<h3 id="安装Rancher"><a href="#安装Rancher" class="headerlink" title="#安装Rancher"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/deploy/mall_swarm_deploy_k8s.html#%E5%AE%89%E8%A3%85rancher">#</a>安装Rancher</h3><ul>
<li>首先需要安装Rancher，先下载Rancher的Docker镜像；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker pull rancher/rancher:v2.5-head</span><br></pre></td></tr></table></figure>

<ul>
<li>下载完成后在Docker容器中运行Rancher服务；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">docker run -p 80:80 -p 443:443 --name rancher \</span><br><span class="line">--privileged \</span><br><span class="line">--restart=unless-stopped \</span><br><span class="line">-d rancher/rancher:v2.5-head</span><br></pre></td></tr></table></figure>

<ul>
<li>Rancher启动成功后，通过如下地址就可以访问它的主页了：<a target="_blank" rel="noopener" href="http://192.168.3.102/">http://192.168.3.102</a></li>
</ul>
<p><img src="https://www.macrozheng.com/assets/mall_swarm_deploy_k8s_02-0f160ac3.png"></p>
<h3 id="修改Nacos配置"><a href="#修改Nacos配置" class="headerlink" title="#修改Nacos配置"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/deploy/mall_swarm_deploy_k8s.html#%E4%BF%AE%E6%94%B9nacos%E9%85%8D%E7%BD%AE">#</a>修改Nacos配置</h3><blockquote>
<p>将项目<code>config</code>目录下的所有配置都添加到Nacos中，由于应用服务都部署到了K8S中，所以需要修改相关配置。</p>
</blockquote>
<ul>
<li>将配置信息添加到Nacos中后显示信息如下，Nacos访问地址：<a target="_blank" rel="noopener" href="http://192.168.3.101:8848/nacos/index.html">http://192.168.3.101:8848/nacos/index.html</a></li>
</ul>
<p><img src="https://www.macrozheng.com/assets/mall_swarm_deploy_k8s_03-0bcd41d2.png"></p>
<ul>
<li>修改<code>mall-admin-prod.yaml</code>配置，修改MySql和Redis连接地址即可，之前是通过<code>--link</code>的形式访问的，这次需要改为IP进行访问；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">spring:</span><br><span class="line">  datasource:</span><br><span class="line">    url: jdbc:mysql://192.168.3.101:3306/mall?useUnicode=true&amp;characterEncoding=utf-8&amp;serverTimezone=Asia/Shanghai</span><br><span class="line">    username: root</span><br><span class="line">    password: root</span><br><span class="line">  redis:</span><br><span class="line">    host: 192.168.3.101 # Redis服务器地址</span><br><span class="line">    database: 0 # Redis数据库索引（默认为0）</span><br><span class="line">    port: 6379 # Redis服务器连接端口</span><br><span class="line">    password: #不设置密码</span><br></pre></td></tr></table></figure>

<ul>
<li>修改<code>mall-gateway-prod.yaml</code>配置，修改Redis连接地址及JWT的publicKey访问地址即可（当在K8S中创建服务后，可以通过服务名进行访问）；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">spring:</span><br><span class="line">  redis:</span><br><span class="line">    host: 192.168.3.101 # Redis服务器地址</span><br><span class="line">    database: 0 # Redis数据库索引（默认为0）</span><br><span class="line">    port: 6379 # Redis服务器连接端口</span><br><span class="line">    password: #不设置密码</span><br><span class="line">  security:</span><br><span class="line">    oauth2:</span><br><span class="line">      resourceserver:</span><br><span class="line">        jwt:</span><br><span class="line">          jwk-set-uri: &#x27;http://mall-gateway-service:8201/mall-auth/rsa/publicKey&#x27;</span><br></pre></td></tr></table></figure>

<ul>
<li>修改<code>mall-portal-prod.yaml</code>配置，修改MySql、MongoDb、Redis、RabbitMq连接地址即可；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">spring:</span><br><span class="line">  datasource:</span><br><span class="line">    url: jdbc:mysql://192.168.3.101:3306/mall?useUnicode=true&amp;characterEncoding=utf-8&amp;serverTimezone=Asia/Shanghai</span><br><span class="line">    username: root</span><br><span class="line">    password: root</span><br><span class="line">  data:</span><br><span class="line">    mongodb:</span><br><span class="line">      host: 192.168.3.101</span><br><span class="line">      port: 27017</span><br><span class="line">      database: mall-port</span><br><span class="line">  redis:</span><br><span class="line">    host: 192.168.3.101 # Redis服务器地址</span><br><span class="line">    database: 0 # Redis数据库索引（默认为0）</span><br><span class="line">    port: 6379 # Redis服务器连接端口</span><br><span class="line">    password: #不设置密码</span><br><span class="line">  rabbitmq:</span><br><span class="line">    host: 192.168.3.101</span><br><span class="line">    port: 5672</span><br><span class="line">    virtual-host: /mall</span><br><span class="line">    username: mall</span><br><span class="line">    password: mall</span><br><span class="line">    publisher-confirms: true #如果对异步消息需要回调必须设置为true</span><br></pre></td></tr></table></figure>

<ul>
<li>修改<code>mall-search-prod.yaml</code>配置，修改MySql、Elasticsearch连接地址即可。</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">spring:</span><br><span class="line">  datasource:</span><br><span class="line">    url: jdbc:mysql://192.168.3.101:3306/mall?useUnicode=true&amp;characterEncoding=utf-8&amp;serverTimezone=Asia/Shanghai</span><br><span class="line">    username: root</span><br><span class="line">    password: root</span><br><span class="line">  elasticsearch:</span><br><span class="line">    rest:</span><br><span class="line">      uris: http://192.168.3.101:9200</span><br></pre></td></tr></table></figure>

<h3 id="使用Rancher部署应用"><a href="#使用Rancher部署应用" class="headerlink" title="#使用Rancher部署应用"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/deploy/mall_swarm_deploy_k8s.html#%E4%BD%BF%E7%94%A8rancher%E9%83%A8%E7%BD%B2%E5%BA%94%E7%94%A8">#</a>使用Rancher部署应用</h3><blockquote>
<p>当使用Rancher创建Deployment时，如果镜像下载过慢会出现超时，可以进入到Rancher容器中手动进行下载。</p>
</blockquote>
<ul>
<li>首先进入Rancher容器内部；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker exex -it rancher /bin/bash</span><br></pre></td></tr></table></figure>

<ul>
<li>通过<code>crictl</code>命令下载应用镜像，下载过程有点慢而且没有进度条，需要耐心等待；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">k3s crictl pull macrodocker/mall-gateway:1.0-SNAPSHOT</span><br><span class="line">k3s crictl pull macrodocker/mall-auth:1.0-SNAPSHOT</span><br><span class="line">k3s crictl pull macrodocker/mall-monitor:1.0-SNAPSHOT</span><br><span class="line">k3s crictl pull macrodocker/mall-admin:1.0-SNAPSHOT</span><br><span class="line">k3s crictl pull macrodocker/mall-portal:1.0-SNAPSHOT</span><br><span class="line">k3s crictl pull macrodocker/mall-search:1.0-SNAPSHOT</span><br></pre></td></tr></table></figure>

<ul>
<li>下载完成后查看镜像显示内容如下；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">root@ae85f823208f:/var/lib/rancher# k3s crictl images |grep macrodocker</span><br><span class="line">docker.io/macrodocker/mall-admin     1.0-SNAPSHOT        15737ce903a94       308MB</span><br><span class="line">docker.io/macrodocker/mall-auth      1.0-SNAPSHOT        72df5f91f2d74       293MB</span><br><span class="line">docker.io/macrodocker/mall-gateway   1.0-SNAPSHOT        4055dfc1e6016       301MB</span><br><span class="line">docker.io/macrodocker/mall-monitor   1.0-SNAPSHOT        492d9bb4375c6       291MB</span><br><span class="line">docker.io/macrodocker/mall-portal    1.0-SNAPSHOT        8dd79675f40c1       312MB</span><br><span class="line">docker.io/macrodocker/mall-search    1.0-SNAPSHOT        f0d0d80c590f1       325MB</span><br></pre></td></tr></table></figure>

<ul>
<li>镜像都下载完成后，我们就可以使用Rancher来可视化创建Deployment了，这里以<code>YAML</code>的方式来创建；</li>
</ul>
<p><img src="https://www.macrozheng.com/assets/mall_swarm_deploy_k8s_04-61d94ce5.png"></p>
<ul>
<li>直接将项目<code>k8s</code>文件夹中的<code>mall-admin-deployment.yaml</code>文件内容复制下即可；</li>
</ul>
<p><img src="https://www.macrozheng.com/assets/mall_swarm_deploy_k8s_05-3795dbb6.png"></p>
<ul>
<li>之后再使用<code>mall-admin-service.yaml</code>文件创建Service；</li>
</ul>
<p><img src="https://www.macrozheng.com/assets/mall_swarm_deploy_k8s_06-6709dccf.png"></p>
<ul>
<li>这里仅以<code>mall-admin</code>应用为例创建Deployment和Service，其他应用创建过程基本相同，脚本均在项目的k8s文件夹中。</li>
</ul>
<p><img src="https://www.macrozheng.com/assets/mall_swarm_deploy_k8s_07-0736a2c5.png"></p>
<h2 id="效果展示"><a href="#效果展示" class="headerlink" title="#效果展示"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/deploy/mall_swarm_deploy_k8s.html#%E6%95%88%E6%9E%9C%E5%B1%95%E7%A4%BA">#</a>效果展示</h2><blockquote>
<p>使用Rancher部署完所有应用服务之后，让我们来看看效果。</p>
</blockquote>
<ul>
<li>首先查看所有创建的Deployment；</li>
</ul>
<p><img src="https://www.macrozheng.com/assets/mall_swarm_deploy_k8s_08-8f798756.png"></p>
<ul>
<li>查看所有创建的Service；</li>
</ul>
<p><img src="https://www.macrozheng.com/assets/mall_swarm_deploy_k8s_09-ae00b0af.png"></p>
<ul>
<li>如果你想查看应用的启动日志，在Pod列表查看即可；</li>
</ul>
<p><img src="https://www.macrozheng.com/assets/mall_swarm_deploy_k8s_10-db0909ab.png"></p>
<ul>
<li>由于应用服务被部署在Rancher容器内部，无法直接访问，我们可以使用Nginx反向代理来访问，Nginx服务运行在<code>2080</code>端口上；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">docker run -p 2080:2080 --name nginx \</span><br><span class="line">-v /mydata/nginx/html:/usr/share/nginx/html \</span><br><span class="line">-v /mydata/nginx/logs:/var/log/nginx  \</span><br><span class="line">-v /mydata/nginx/conf:/etc/nginx \</span><br><span class="line">-d nginx:1.10</span><br></pre></td></tr></table></figure>

<ul>
<li>接下来需要获得Rancher容器运行的IP地址，使用如下命令即可；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[root@linux-local ~]# docker inspect rancher |grep IPAddress</span><br><span class="line">            &quot;SecondaryIPAddresses&quot;: null,</span><br><span class="line">            &quot;IPAddress&quot;: &quot;172.17.0.2&quot;,</span><br><span class="line">                    &quot;IPAddress&quot;: &quot;172.17.0.2&quot;,</span><br></pre></td></tr></table></figure>

<ul>
<li>创建完Nginx容器后，添加配置文件<code>api.conf</code>，将<code>api.macrozheng.com</code>域名的访问反向代理到K8S中的<code>mall-gateway-service</code>服务上去；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">server &#123;</span><br><span class="line">    listen       2080;</span><br><span class="line">    server_name  api.macrozheng.com; #修改域名</span><br><span class="line"></span><br><span class="line">    location / &#123;</span><br><span class="line">        proxy_set_header Host $host:$server_port;</span><br><span class="line">        proxy_pass   http://172.17.0.2:30201; #修改为代理服务地址</span><br><span class="line">        index  index.html index.htm;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    error_page   500 502 503 504  /50x.html;</span><br><span class="line">    location = /50x.html &#123;</span><br><span class="line">        root   /usr/share/nginx/html;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>再修改访问Linux服务器的本机host文件，添加如下记录；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">192.168.3.102 api.macrozheng.com</span><br></pre></td></tr></table></figure>

<ul>
<li>其实也可以不用Nginx来进行反向代理，创建容器的时候将<code>mall-gateway-service</code>的端口映射出来即可；</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">docker run -p 80:80 -p 443:443 -p 8201:30201 --name rancher \</span><br><span class="line">--privileged \</span><br><span class="line">--restart=unless-stopped \</span><br><span class="line">-d rancher/rancher:v2.5-head</span><br></pre></td></tr></table></figure>

<ul>
<li>通过Nginx即可访问<code>mall-swarm</code>的接口文档，访问地址：<a target="_blank" rel="noopener" href="http://api.macrozheng.com:2080/doc.html">http://api.macrozheng.com:2080/doc.html</a></li>
</ul>
<p><img src="https://www.macrozheng.com/assets/mall_swarm_deploy_k8s_11-ed955450.png"></p>
<h2 id="总结"><a href="#总结" class="headerlink" title="#总结"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/deploy/mall_swarm_deploy_k8s.html#%E6%80%BB%E7%BB%93">#</a>总结</h2><p>通过把<code>mall-swarm</code>项目部署到K8S上，我们可以发现K8S也没有想象中到那么难，K8S中的很多东西都是和Docker相通的！当我们听到消息称某个新技术要取代旧技术了，往往会困惑我们学的那些旧技术是不是过时了，没用了？其实我们大可不必担心，往往新技术都是在旧技术的基础上产生的，而且那些会旧技术的人会更容易掌握新技术！</p>
<h2 id="K8S系列教程"><a href="#K8S系列教程" class="headerlink" title="#K8S系列教程"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/deploy/mall_swarm_deploy_k8s.html#k8s%E7%B3%BB%E5%88%97%E6%95%99%E7%A8%8B">#</a>K8S系列教程</h2><blockquote>
<p>再次推荐一波我的K8S系列教程，K8S实战看这些就对了！</p>
</blockquote>
<ul>
<li><a target="_blank" rel="noopener" href="https://mp.weixin.qq.com/s/N-9xVPYO_VVL5JZu5UPbtQ">K8S太火了！花10分钟玩转它不香么？open in new window</a></li>
<li><a target="_blank" rel="noopener" href="https://mp.weixin.qq.com/s/dwrxKr4ONfzCLn01QbkpQg">自从上了K8S，项目更新都不带停机的！open in new window</a></li>
<li><a target="_blank" rel="noopener" href="https://mp.weixin.qq.com/s/RXAQtsNXUS2kiSCMFDxKqA">我把SpringBoot应用部署到了K8S上，怎么感觉用起来像Docker！open in new window</a></li>
<li><a target="_blank" rel="noopener" href="https://mp.weixin.qq.com/s/NOkaYGz9ZT3bsG1J7yXVRA">再见命令行！K8S傻瓜式安装，图形化管理真香！open in new window</a></li>
<li><a target="_blank" rel="noopener" href="https://mp.weixin.qq.com/s/a7w2qvDg8c2BEQU7A1NqaA">看看人家那开源项目文档写的，那叫一个友好！open in new window</a></li>
<li><a target="_blank" rel="noopener" href="https://mp.weixin.qq.com/s/iDG7Wzq9DQHLFPtnqokOxQ">据说只有高端机器才配运行K8S，网友：1G内存的渣渣跑起来了！open in new window</a></li>
<li><a target="_blank" rel="noopener" href="https://mp.weixin.qq.com/s/jBP7E7DL5vJ0zp5UnSFNBg">再见 Docker ！5分钟转型 containerd !open in new window</a></li>
</ul>
<h2 id="项目源码地址"><a href="#项目源码地址" class="headerlink" title="#项目源码地址"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/deploy/mall_swarm_deploy_k8s.html#%E9%A1%B9%E7%9B%AE%E6%BA%90%E7%A0%81%E5%9C%B0%E5%9D%80">#</a>项目源码地址</h2><p><a target="_blank" rel="noopener" href="https://github.com/macrozheng/mall-swarm">https://github.com/macrozheng/mall-swarm</a></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="https://ko25891wan.gitlab.io">十一星野</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="https://ko25891wan.gitlab.io/2024/01/98cfc2cb76b4.html">https://ko25891wan.gitlab.io/2024/01/98cfc2cb76b4.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://ko25891wan.gitlab.io" target="_blank">小小程序员</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2024/01/9e3e1c27170c.html" title="mall-swarm在Linux环境下的部署（基于Docker容器）"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">mall-swarm在Linux环境下的部署（基于Docker容器）</div></div></a></div><div class="next-post pull-right"><a href="/2024/01/ae834480f808.html" title="mall-swarm使用Jenkins实现自动化部署"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">mall-swarm使用Jenkins实现自动化部署</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">十一星野</div><div class="author-info__description">归途也还可爱</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">120</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">4</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">22</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://gitlab.com/ko25891wan/ko25891wan.gitlab.io"><i class="fab fa-github"></i><span>关注我</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitlab.com/ko25891wan/ko25891wan.gitlab.io" target="_blank" title="Github"><i class="fab fa-github" style="color: #24292e;"></i></a><a class="social-icon" href="https://gitlab.com/ko25891wan/ko25891wan.gitlab.io" target="_blank" title="Gitlab"><i class="fab fa-gitlab" style="color: #24292e;"></i></a><a class="social-icon" href="mailto:ko25891wan@outlook.com" target="_blank" title="Email"><i class="fas fa-envelope" style="color: #4a7dbe;"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9C%8D%E5%8A%A1%E5%99%A8%E8%A7%84%E5%88%92"><span class="toc-number">1.</span> <span class="toc-text">服务器规划</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%95%9C%E5%83%8F%E6%89%93%E5%8C%85%E5%8F%8A%E6%8E%A8%E9%80%81"><span class="toc-number">2.</span> <span class="toc-text">镜像打包及推送</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9F%BA%E7%A1%80%E6%9C%8D%E5%8A%A1%E5%99%A8%E9%83%A8%E7%BD%B2"><span class="toc-number">3.</span> <span class="toc-text">基础服务器部署</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%BA%94%E7%94%A8%E6%9C%8D%E5%8A%A1%E5%99%A8%E9%83%A8%E7%BD%B2"><span class="toc-number">4.</span> <span class="toc-text">应用服务器部署</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%89%E8%A3%85Rancher"><span class="toc-number">4.1.</span> <span class="toc-text">安装Rancher</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9Nacos%E9%85%8D%E7%BD%AE"><span class="toc-number">4.2.</span> <span class="toc-text">修改Nacos配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8Rancher%E9%83%A8%E7%BD%B2%E5%BA%94%E7%94%A8"><span class="toc-number">4.3.</span> <span class="toc-text">使用Rancher部署应用</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%88%E6%9E%9C%E5%B1%95%E7%A4%BA"><span class="toc-number">5.</span> <span class="toc-text">效果展示</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%80%BB%E7%BB%93"><span class="toc-number">6.</span> <span class="toc-text">总结</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#K8S%E7%B3%BB%E5%88%97%E6%95%99%E7%A8%8B"><span class="toc-number">7.</span> <span class="toc-text">K8S系列教程</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%A1%B9%E7%9B%AE%E6%BA%90%E7%A0%81%E5%9C%B0%E5%9D%80"><span class="toc-number">8.</span> <span class="toc-text">项目源码地址</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/02/c60470b9a892.html" title="Java集合使用注意事项总结">Java集合使用注意事项总结</a><time datetime="2024-02-03T04:58:22.000Z" title="发表于 2024-02-03 12:58:22">2024-02-03</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/02/81fb7a201f29.html" title="无题">无题</a><time datetime="2024-02-03T03:15:31.812Z" title="发表于 2024-02-03 11:15:31">2024-02-03</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/01/5737c1ec69a9.html" title="Wed Jan 17 2024 00:00:00 GMT+0800 (中国标准时间)">Wed Jan 17 2024 00:00:00 GMT+0800 (中国标准时间)</a><time datetime="2024-01-31T06:56:16.000Z" title="发表于 2024-01-31 14:56:16">2024-01-31</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/01/f510db7d2f19.html" title="Spring常见面试题总结">Spring常见面试题总结</a><time datetime="2024-01-31T06:55:58.000Z" title="发表于 2024-01-31 14:55:58">2024-01-31</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/01/9be065e9f288.html" title="redis 面试">redis 面试</a><time datetime="2024-01-31T06:55:55.000Z" title="发表于 2024-01-31 14:55:55">2024-01-31</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2023 - 2024 By 十一星野</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">简</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.staticfile.org/fancyapps-ui/5.0.32/fancybox/fancybox.umd.min.js"></script><script src="https://cdn.staticfile.org/instant.page/5.2.0/instantpage.min.js" type="module"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></div></body></html>